﻿using System.Collections.Generic;
using System.Linq;

namespace Tuxedo.Compile
{
	internal class MultiplicativeExpression : Expression
	{
		public Expression[] Expressions { get; private set; }
		public char[] Ops { get; private set; }

		public MultiplicativeExpression(IList<Expression> expressions, IList<string> ops)
		{
			this.SimplifyConstantValues(expressions, ops);

			this.Expressions = expressions.ToArray();
			char[] charOps = new char[ops.Count];
			for (int i = 0; i < ops.Count; ++i)
			{
				charOps[i] = ops[i][0];
			}
			this.Ops = charOps;
		}

		protected override Expression DoConstantSimplification(Constant left, Constant right, string op)
		{
			if (op == "*")
			{
				return left.Multiply(right);
			}

			if (op == "/")
			{
				return left.Divide(right);
			}

			return left.Modulo(right);
		}
	}
}
